-
Notifications
You must be signed in to change notification settings - Fork 17
fix: Unify Actor context manager with init & exit methods #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fcec3b9 to
3dacd65
Compare
|
Am not sure about this. What about this scenario? This used to work before, but now it will try to call |
|
IMO that scenario is a misuse. You've got 2 approaches and you should choose one of them. Not combining them. |
|
People can use Can we keep a flag to know the exit method was already called, and skip the duplicated logic that would be otherwise produced by the context manager? |
|
I added one test. We can decide whether it is an allowed use case that should be supported or a misuse. |
janbuchar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Judging by https://github.com/apify/apify-sdk-python/pull/600/files#diff-807ba3710b8cdf01f23374c98d85a91075d4b602c8c4a3b46ddb64696b16987d I suppose the point raised by @Pijukatel has been resolved?
|
If you mean this:
Then yes, this is a valid scenario (we have the |
|
@janbuchar @Pijukatel could you guys take another look? Thanks. |
Pijukatel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actor.fail should jump out of the context, but it does not. The test I added earlier was removed, but it can be seen there:
Without this, the user will not be able to fail/exit Actor from request handlers.
async def test_actor_fail_prevents_further_execution(caplog: pytest.LogCaptureFixture) -> None:
async with Actor:
await Actor.fail(exit_code=2, exception=Exception('abc'), status_message='cde')
raise RuntimeError('This should not trigger')
assert caplog.records[-3].levelno == logging.ERROR # type: ignore[unreachable]
assert caplog.records[-3].msg == 'Actor failed with an exception'
assert caplog.records[-3].exc_text == 'Exception: abc'
assert caplog.records[-2].levelno == logging.INFO
assert caplog.records[-2].msg == 'Exiting Actor'
assert caplog.records[-1].levelno == logging.INFO
assert caplog.records[-1].msg == '[Terminal status message]: cde'
|
@Pijukatel The test is back and fixes. |
Description
To align the behavior between the two possible approaches of using an Actor - as a context manager or by explicitly calling
init/exit/fail- the following changes were implemented:exit_code,status_message,event_listeners_timeout,cleanup_timeout) were added to theActor.__init__as well.exit_codeandstatus_messageare now public properties with setters, allowing them to be updated within a context manager block in response to error conditions.__aenter__frominitand__aexit__fromexitwas reversed, ensuring fewer inconsistencies for future changes (since__aenter__and__aexit__have a fixed number of arguments).Other changes:
Issues
Testing